﻿//-----------------------------------------------------------------------
// <author>Paul Long</author>
//-----------------------------------------------------------------------

namespace NMCaptureData
{
    /// <summary>
    /// Calculates throughput
    /// </summary>
    internal static class CalcThroughput
    {
        #region States

        /// <summary>
        /// Used to convert 8 Bits to a byte.
        /// </summary>
        private const uint BitsPerByte = 8;

        /// <summary>
        /// Used to convert 8 Bits to a byte.
        /// </summary>
        private const double SecondsPerTimeTick = 10000.0;

        #endregion

        #region Methods

        /// <summary>
        /// Computes the throughput.
        /// </summary>
        /// <param name="byteCount">Number of bytes transfered</param>
        /// <param name="timeDifference">Time difference</param>
        /// <returns>returns the throughput</returns>
        public static double Throughput(uint byteCount, ulong timeDifference)
        {
            double throughputReturn;

            if (timeDifference <= 0)
            {
                throughputReturn = 0;
            }
            else
            {
                throughputReturn = (double)(byteCount * BitsPerByte) / (double)timeDifference * SecondsPerTimeTick;
            }

            return throughputReturn;
        }

        #endregion
    }
}
